import {
  mapState,
  mapMutations,
  mapActions
} from "vuex";

import {
  getmessage_count,
  LtLongIn,
  get_threetimes_addmoneywindow
} from "@/assets/api/userCenterApi";
import MiddleUtil from "@/assets/utils/MiddleUtil";

import {
  getUserActivity,
  getwendawindow,
} from "@/assets/api/indexApi";

import {
  getDiffDay
} from "@/assets/utils/utils.js";

import GoEasy from "goeasy";




function getShowMessage(item) {
  if (item.extendedData == 11) return "[图片]";
  else if (item.extendedData == 111) return "[表情]";
  else return item.message;
}


export default {
  data() {
    return {
      CouponShow: false,
      CouponGetType: 2,
      getAdminCoupon: 0,
      getDiscountSwitch: true,
      myMusic: null,

      showLeafType: 1,
      moenyShow: false,
      leafNum: 0,
      leafPopup: false,
      
      UserActivity30Obj: null,
      UserActivity30Show: false
    };
  },
  computed: {
    ...mapState("common", {
      userInfo: (state) => state.userInfo,
      // zim: (state) => state.zim,
      goeasyObj: (state) => state.goeasyObj,
    }),
  },
  mounted() {
    let that = this
    this.openWebPage();

  },
  methods: {
    ...mapMutations("common", [
      "set_messageCount",
      "updata_ConversationList",
      "set_goeasyObj",
    ]),
    ...mapMutations("quiz", ["set_entering"]),
    ...mapActions("common", [
      "createZIM",
      "ZIMLogin",
      "getUserInfo2",
    ]),



    // 打开页面检查是否登录，登录后做相应处理
    openWebPage(is = false) {
      if (localStorage.getItem("token")) {
        let that = this;
        setTimeout(() => {
          that.getUserInfo2()
            .then((user) => {
              if (user) {

                if (that.$route.path == '/cswd') {
                  // 检查有没有获取到优惠券
                  // that.getwendawindow();
                  if (user.activity_reward == '30') that.getDiscount();
                }
              }
            })
            .catch(() => {});
        }, 100);
      }
    },

    async LtLongIn() {
      const res = await LtLongIn({})
      if (res.data.is_show == 1) {
        this.leafPopup = true;
        this.showLeafType = 1;
        this.leafNum = 1000;
        if (this.leafPopup) {
          const res2 = await getUserActivity({
            activity_id: 2
          })
          this.moenyShow = true
        }
      }
    },

    async get_threetimes_addmoneywindow() {
      const res = await get_threetimes_addmoneywindow({})
      if (res.data.is_show == 1) {
        this.leafPopup = true;
        this.showLeafType = 2;
        this.leafNum = 2000;
        if (this.leafPopup) {
          const res2 = await getUserActivity({
            activity_id: 3
          })
          this.moenyShow = true
        }
      }
    },



    // 去掉奖励弹窗
    async getDiscount() {

      if (this.getDiscountSwitch == false) return;
      this.getDiscountSwitch = false;
      const res = await getUserActivity({
        activity_id: 31,
      });
      if (res.code == 1) {
        this.UserActivity30Obj = res.data;
        this.UserActivity30Show = true
        this.getDiscountSwitch = true;
      }
    },

    // 获取问答优惠券
    async getwendawindow() {
      const res = await getwendawindow({});
      if (res.code == 1 && res.data > 0) {
        this.getAdminCoupon = res.data;
        this.CouponShow = true;
      }
    },




  }
};
